package cn.tianyigps.tianyigpsguazi.Utils;

import org.springframework.util.StringUtils;

/**
 * cn.tianyigps.tianyigpsguazi.Utils
 * 方向字符串转二维坐标系参数
 * @author zgl
 * @create 2019-03-23 16:11
 */
 
public class DirectionUtils {

    public static Integer transfer(String string){
        Integer direction = null;
        switch (string){
            case "正北":
                direction =90;
                break;
            case "正东":
                direction = 0;
                break;
            case  "正西":
                direction = 180;
                break;
            case  "正南":
                direction = 270;
                break;
            case  "静止":
                //静止状态继续为null
                break;
            default:
                    string = string.substring(0,string.length()-1);
                    String direct = string.substring(0,3);
                    String str = string.substring(4);
                    try{
                    Integer num = Integer.valueOf(str.substring(0,string.length()-1));
                    switch (direct)
                    {
                        case  "北偏东":
                            direction = 90 - num;
                            break;
                        case  "西偏北":
                            direction = 180 - num;
                            break;
                        case  "南偏西":
                            direction = 270 - num;
                            break;
                        case  "东偏南":
                            direction = 360 - num;
                            break;
                        default:
                            break;
                    } }catch (ClassCastException e){
                        e.printStackTrace();
                    }
                break;
        }
        return  direction;
    }
}
